<!doctype html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <title>城市管理</title>
	    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
      <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
      <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    </head>
    <body>
       <div class="easyui-container-fluid">
          <div class="easyui-panel" style="border:none;">
            <div class="nav" id="nav"></div> 
            <div class="easyui-panel">
                <div style="margin-bottom:20px;">
                  <label class="item-label">代码：</label>
                  <input type="text" name="code" class="easyui-textbox" style="width:100px;"/>
                  <label class="item-label">市县：</label>
                  <input type="text" name="name"  class="easyui-textbox" style="width:100px;"/>
                  <label class="item-label">省份：</label>
                  <select name="provinceCode" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;">
                  </select>
                  <label class="item-label">隶属城市：</label>
                  <select name="belongCityCode" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;">
                  </select>         
                </div>
                <div style="margin-bottom:20px;">
                  <label class="item-label">市场级别：</label>
                  <select name="marketLevel.name" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;">
                      <option value="">-请选择-</option>
                      <option value="value1">一级市场</option>
                      <option value="value2">二级市场</option>
                      <option value="value3">三级市场</option>
                      <option value="value4">四级市场</option>
                  </select>
                  <label class="item-label">城市级别：</label>
                  <select name="cityLevelCode" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;">
                      <option value="">-请选择-</option>
                      <option value="1">一线城市</option>
                      <option value="2">二线城市</option>
                      <option value="3">三线城市</option>
                      <option value="4">县域城市</option>
                  </select>
                  <label class="item-label">南北方：</label>
                  <select name="north" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;">
                      <option value="">-请选择-</option>
                      <option value="true">北方</option>
                      <option value="false">南方</option>      
                  </select>
                  <label class="item-label">城市区域：</label>
                  <select name="areaCode" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;">
                      <option value="">-请选择-</option>
                      <option value="1">东北地区</option>
                      <option value="2">华北地区</option>
                      <option value="3">华东地区</option>
                      <option value="4">华南地区</option>    
                      <option value="5">华中地区</option>
                      <option value="6">西南地区</option>
                      <option value="7">西北地区</option>
                  </select>
                </div>
                <div style="text-align:center;margin-bottom:20px;">
                  <a class="easyui-linkbutton c8" style="width:80px;" href="javascript:void(0);" onclick="searchBy()">查询</a>
                </div>
            </div>
            <div class="table-wrapper">
             <table id="datagrid" class="easyui-datagrid">
               <thead>
                 <tr>
                   <th data-options="field:'code',align:'center'" width="80">代码</th>
                   <th data-options="field:'province',align:'center',formatter:subProFormatter" width="100">省份</th>
                   <th data-options="field:'name',align:'center'" width="100">市/县</th>
                   <th data-options="field:'belongingCity',align:'center',formatter:subProFormatter" width="100">隶属城市</th>
                   <th data-options="field:'cityLevel',align:'center',formatter:subProFormatter" width="100">城市级别</th>
                   <th data-options="field:'cityScale',align:'center',formatter:subProFormatter" width="80">城市规模</th>
                   <th data-options="field:'marketLevel',align:'center',formatter:subProFormatter" width="100">市场级别</th>
                   <th data-options="field:'north',align:'center'" width="80">南北方</th>
                   <th data-options="field:'areaCode',align:'center',formatter:subProFormatter" width="100">城市区域</th>
                   <th data-options="field:'entityStatus',align:'center',formatter:statusFormatter" width="80">状态</th>
                   <th data-options="field:'action',align:'center',formatter:actions" width="194">操作</th>
                 </tr>
               </thead>
               <tbody>
               </tbody>
             </table>
           </div>
          </div> 
       </div>  
    </body>
    <script type="text/javascript">
           $(function(){
               setNav();
               $("#datagrid").datagrid({
                   pagination:true,
                   rownumbers:true,
                   toolbar:[{
                        text:'添加城市',
                        handler:function(){
                          window.parent.addTab("添加城市","../channel/city/add.html");
                        }
                      }]
               });
               $.ajax({
                   url:config.url + "/city",
                   type:"get",
                   data:{size:10},
                   xhrFields:{withCredentials:true},
                   success:function(data){
                      $("#datagrid").datagrid({data:data.content}).datagrid("getPager").pagination({
                        pageList:[10,15,20,25,30,35,40,50,100],
                        displayMsg:"共"+data.totalElements+"条记录"
                      });
                   },
                   error:function(data){
                      console.log(data);
                   }
               });

           });
           function actions(val,row){
                return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px' "+
               "onclick='edit(\""+row.id+"\")'>修改</a>&nbsp;&nbsp;"+
               "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px' "+
               "onclick='disableOne(\""+row.id+"\")'>禁用</a>";
            }
            function edit(id){
                window.location.href = "./add.html?id="+id;
            }
            function disableOne(data){
                $.messager.confirm("提示","您确定禁用该记录吗？",function(flag){
                     if(flag){
                        $.ajax({
                            url:config.url+"/city/"+data,
                            type:'DELETE',
                            xhrFields:{withCredentials:true},
                            success:function(data){
                                $.messager.alert("提示","操作成功");
                                $.ajax({
                                   url:config.url + "/city",
                                   type:"get",
                                   data:{size:10},
                                   xhrFields:{withCredentials:true},
                                   success:function(data){
                                      $("#datagrid").datagrid({data:data.content}).datagrid("getPager").pagination({
                                        pageList:[10,15,20,25,30,35,40,50,100],
                                        displayMsg:"共"+data.totalElements+"条记录"
                                      });
                                   },
                                   error:function(data){
                                      console.log(data);
                                   }
                               });
                            },
                            error(XMLHttpRequest,textStatus,thrown){

                            }
                        });
                     }
                });
           }

           function searchBy(){
              var data = getFormData(document.getElementById("ff"));
              $.ajax({
                   url:config.url + "/city",
                   type:"get",
                   data:transfer(data),
                   xhrFields:{withCredentials:true},
                   success:function(data){
                      $("#datagrid").datagrid({data:data.content}).datagrid("getPager").pagination({
                        pageList:[10,15,20,25,30,35,40,50,100],
                        displayMsg:"共"+data.totalElements+"条记录"
                      });
                   },
                   error:function(data){
                      console.log(data);
                   }
               });
           }
           function subProFormatter(val){
              return val?val.name:"";
           }
      </script>
</html>
